package com.scrat.huzhenjie.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class HtmlPost {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String link = "http://developer.baidu.com/bae/bcs/key/getsign";
		StringBuilder result = new StringBuilder();
		OutputStream os = null;
		try {
			URL url = new URL(link);
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			conn.setDoOutput(true);
			conn.setRequestMethod("POST");
			conn.setRequestProperty("User-Agent", "Mozilla/5.0");
//			conn.setRequestProperty("cookie", cookieval);
			StringBuilder sb = new StringBuilder("host=bcs.duapp.com&ak=E4ea8cb7301ecf89c973a17737ee621d&sk=384f9ee83b10d3d83375472db8784ba4&bucket=huzhenjie&object=%2Fvim_go.png&ip=&size=&date=");
//			sb.append("ak=").append("E4ea8cb7301ecf89c973a17737ee621d").append("&sk=")
//					.append("384f9ee83b10d3d83375472db8784ba4").append("&bucket=").append("huzhenjie").append("&object=").append("/test.sh");
			os = conn.getOutputStream();
			os.write(sb.toString().getBytes("UTF-8"));
			BufferedReader br = new BufferedReader(new InputStreamReader(
					conn.getInputStream()));
			conn.connect();
			String line = br.readLine();
			while (line != null) {
				line = br.readLine();
				result.append(line);
			}
		} catch (Exception e) {
		} finally {
			if (os != null) {
				try {
					os.close();
				} catch (IOException e) {
				}
			}
		}
		System.out.println("result:"+result.toString());
	}

}
